<%--
  Created by IntelliJ IDEA.
  User: wwh
  Date: 2017/8/9
  Time: 10:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>创建对应学院岗位类别</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/global.css">
    <link rel="stylesheet" href="../../static/css/table.css">
    <script type="text/javascript" src="/static/common/layui/layui.js"></script>
    <script type="text/javascript" src="/static/common/vue.min.js"></script>
    <script type="text/javascript" src="/static/common/axios.min.js"></script>
</head>
<body>
<div style="margin:15px;" id="Vue">
    <blockquote class="layui-elem-quote">
        <form action="" method="post" class="layui-form">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <a href="#" class="layui-btn layui-btn-small" @click="addPositionType">
                        <i class="layui-icon">&#xe608;</i> 创建岗位
                    </a>
                </div>
                <%--<div class="layui-input-inline">--%>
                    <%--<select id="postype" name="postype" class="layui-input" lay-filter="postype" lay-search>--%>
                        <%--<option value="">选择岗位类别</option>--%>
                        <%--<option value="0">不清楚</option>--%>
                        <%--<option value="1">技术岗</option>--%>
                        <%--<option value="2">非技术岗</option>--%>
                    <%--</select>--%>
                <%--</div>--%>
            <%--<input type="reset" class="layui-btn" value="重置" @click="reset">--%>
        </div>
        </form>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>岗位类别信息</legend>
        <div class="layui-field-box layui-form">
            <table class="layui-table admin-table">
                <thead>
                <tr>
                    <th>岗位名称</th>
                    <th>操作</th>
                </tr>
                </thead>
                <%--内容容器--%>
                <tbody id="content">
                </tbody>
            </table>
        </div>
    </fieldset>
    <%--分页容器--%>
    <div class="admin-table-page">
        <div id="paged" class="page">
        </div>
    </div>
</div>
<!--获得当前用户信息-->
<script>
    var userId = ${sessionScope.currentUser.getId()};
    var schoolAdmin = {};
    axios.get('/schoolMangerInfo/findByUserId/'+userId)
        .then(function (response) {
            schoolAdmin = response.data.data;
        })
        .catch(function (msg) {
            console.log(msg);
        });
</script>
<!--分页模板-->
<script type="text/html" id="tpl">
    {{# layui.each(d.data,function(index,item){ }}
    <tr>
        <td>{{ item.typename||"-" }}</td>
        <td>
            <%--<a href="javascript:;" target="_self" data-id="{{ item.id }}" data-opt="edit" class="layui-btn layui-btn-mini">编辑</a>--%>
            <a href="javascript:;" target="_self" data-id="{{ item.id }}" data-opt="remove" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
        </td>
    </tr>
    {{# }); }}
</script>
<script>
    layui.config({
        base: '/static/js/layuiModulesEX/'
    });
    layui.use(['paging', 'form', 'layer','formverify'],function () {
        var $ = layui.jquery,
            paging = layui.paging(),
            layer = layui.layer,
            form = layui.form(),
            formverify = layui.formverify;

        var vm = new Vue({
            el:"#Vue",
            data:{
                user:{
                    id:userId
                },
                positionType:{
                    schoolid:schoolAdmin.schoolid
                }
            },
            methods:{
                /**
                 * 创建岗位
                 */
                addPositionType:function () {
                    $.get('/schoolAdmin/addPositionType',null,function (html) {
                        layer.open({
                            type:1,
                            title:"岗位信息",
                            area: ['700px', '300px'],
                            content:html,
                            success:function (layero,index) {
                                form.render();
                                // 监听
                                form.on("submit(createPosition)",function (data) {
                                    console.log(data);
                                    var position = {
                                        schoolid:schoolAdmin.schoolid,
                                        typename:data.field.typename
//                                        postype:data.field.postype
                                    };
//                                    if(position.postype === ''){
//                                        position.postype = 0;
//                                    }
                                    console.log(position);
//                                    axios.post('/PositionType/addOne',position)
//                                        .then(function (response) {
//                                            console.log(response.data);
//                                            layer.msg("创建成功",{icon:1,time:1500},function () {
//                                                paging.get();
//                                                layer.close(index);
//                                            });
//                                        })
//                                        .catch(function (msg) {
//                                            console.log(msg);
//                                            layer.msg("系统异常，创建失败",{icon: 5,time:1500},function () {
//                                                layer.close(index);
//                                            });
//                                        })
                                    return false;
                                });
                                return false;
                            },
                            end:function (layero,index) {
                                layer.close(index);
                            }
                        })
                    });
                },
                reset:function () {
                    paging.get({schoolid:schoolAdmin.schoolid,postype:''});
                }
            }
        });

        form.render();
        paging.init({
            openWait:true,
            url:'/PositionType/findBatchByCondition',
            params:{
                schoolid:schoolAdmin.schoolid
            },
            elem:"#content",
            contentType: "application/json; charset=utf-8",
            type: 'POST',
            tempElem: '#tpl', //模块容器
            pageConfig: { //分页参数配置
                elem: 'paged', //分页容器
                pageSize: 10 //分页大小
            },
            success:function () {
                // alert('渲染成功');
            },
            fail:function () {
                // alert('获取数据失败')
            },
            complate:function () {
//                 alert('处理完成');
                $('#content').children('tr').each(function () {
                    var $that = $(this).children('td:last-child');
                    var id = $that.children('a[data-opt=remove]').data('id');
//                    console.log(id);
                    // 删除
                    $that.children('a[data-opt=remove]').on('click',function () {
                        console.log(id);
                        layer.confirm("确认删除吗？",function (index) {
                            axios.get('/PositionType/deleteOneById/'+id)
                                .then(function (response) {
                                    console.log(response.data);
                                    layer.msg(response.data.message);
                                    paging.get();
                                })
                                .catch(function (msg) {
                                    console.log(msg);
                                })
                        });
                    });
                });
            }
        });

        form.on("select(postype)",function (data) {
            console.log(data.value);
            paging.get({schoolid:schoolAdmin.schoolid,postype:data.value})
        });
    });
</script>
</body>
</html>
